package cn.hchaojie.spring.day01;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class DemoSpring {
	@Test
	public void test1() {
		PostService service = new PostService();
		service.delete();
	}
	
	@Test
	public void testSpring() {
		// 从xml文件里面，初始化spring容器
		ApplicationContext context = new ClassPathXmlApplicationContext("context.xml");
		
		PostService bean = context.getBean(PostService.class);
		bean.delete();
	}
	
	@Test
	public void testDependencyInject() {
		// 从xml文件里面，初始化spring容器
		ApplicationContext context = new ClassPathXmlApplicationContext("context.xml");
		
		PostService bean = context.getBean(PostService.class);
		bean.delete();
	}
	
	/** 
	 * bean被创建了几次？
	 * 默认情况下创建的bean是个单例 singleton
	 * 
	 */
	@Test
	public void test2() {
		// 从xml文件里面，初始化spring容器
		ApplicationContext context = new ClassPathXmlApplicationContext("context.xml");
		
		PostService bean1 = context.getBean(PostService.class);
		PostService bean2 = context.getBean(PostService.class);
		
		System.out.println(bean1);
		System.out.println(bean2);
		
	}
	
	/** 
	 * bean被创建了几次？
	 * 
	 */
	@Test
	public void test3() {
		// 从xml文件里面，初始化spring容器
		ApplicationContext context = new ClassPathXmlApplicationContext("context.xml");
	
		PostDao bean1 = context.getBean(PostDao.class);
		PostDao bean2 = context.getBean(PostDao.class);
//		
		System.out.println(bean1);
		System.out.println(bean2);
		
	}
}
